package com.ijiuchuang.jc_localization.view.adapter;

import android.content.Context;

import com.ijiuchuang.jc_localization.R;
import com.ijiuchuang.jc_localization.bean.api.News;
import com.ijiuchuang.jc_localization.tools.adapter.ViewHolder;
import com.ijiuchuang.jc_localization.tools.adapter.recyclerview.MultiItemCommonAdapter;
import com.ijiuchuang.jc_localization.tools.adapter.recyclerview.MultiItemTypeSupport;

import java.util.List;

/**
 * Created by Administrator on 2016/5/19
 */
public class NewsMultiAdapter extends MultiItemCommonAdapter<News.ShowapiResBodyBean.PagebeanBean.ContentlistBean> {

    public NewsMultiAdapter(Context context, List<News.ShowapiResBodyBean.PagebeanBean.ContentlistBean> datas) {
        super(context, datas, new MultiItemTypeSupport<News.ShowapiResBodyBean.PagebeanBean.ContentlistBean>(){

            @Override
            public int getLayoutId(int itemType) {
                switch (itemType) {
                    case 0:
                        return R.layout.list_item_news_no_pic;
                    case 1:
                        return R.layout.list_item_news_single_pic;
                    case 2:
                        return R.layout.list_item_news_single_pic;
                    case 3:
                        return R.layout.list_item_news_multi_pics;
                    default:
                        return R.layout.list_item_news_multi_pics;
                }
            }

            @Override
            public int getItemViewType(int position, News.ShowapiResBodyBean.PagebeanBean.ContentlistBean item) {
                switch (item.getImageurls().size()) {
                    case 0:
                        return 0;
                    case 1:
                        return 1;
                    case 2:
                        return 1;
                    case 3:
                        return 2;
                    default:
                        return 2;
                }
            }
        });
    }

    @Override
    public void convert(ViewHolder holder, News.ShowapiResBodyBean.PagebeanBean.ContentlistBean item) {
        switch (holder.getLayoutId()){
            case R.layout.list_item_news_no_pic:
                holder.setText(R.id.list_item_news_no_text_title, item.getTitle());
                holder.setText(R.id.list_item_news_no_text_desc, item.getDesc());
                holder.setText(R.id.list_item_news_no_text_source, item.getSource());
                holder.setText(R.id.list_item_news_no_text_date, item.getPubDate());
                break;
            case R.layout.list_item_news_single_pic:
                holder.setText(R.id.list_item_news_single_text_title, item.getTitle());
                holder.setText(R.id.list_item_news_single_text_desc, item.getDesc());
                holder.setText(R.id.list_item_news_single_text_source, item.getSource());
                holder.setText(R.id.list_item_news_single_text_date, item.getPubDate());
                holder.setImageByUrl(R.id.list_item_news_single_image, item.getImageurls().get(0).getUrl());
                break;
            case R.layout.list_item_news_multi_pics:
                holder.setText(R.id.list_item_news_multi_text_title, item.getTitle());
                holder.setText(R.id.list_item_news_multi_text_source, item.getSource());
                holder.setText(R.id.list_item_news_multi_text_date, item.getPubDate());
                holder.setImageByUrl(R.id.list_item_news_multi_image1, item.getImageurls().get(0).getUrl());
                holder.setImageByUrl(R.id.list_item_news_multi_image2, item.getImageurls().get(1).getUrl());
                holder.setImageByUrl(R.id.list_item_news_multi_image3, item.getImageurls().get(2).getUrl());
                break;
        }
    }
}
